package test;

import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.List;

public class Util {

	
	public static String generate(){
		
		String html1 = "<html>\n";
		String html2 = "</html>\n";
		String head1 = "<head>\n";
		String head2 = "</head>\n";
		String body1 = "<body>\n";
		String body2 = "</body>\n";
		
		String p1= "<p>";
		String p2= "</p>\n";
		
		String result = html1+head1+head2+body1+p1+"Hola que tal"+p2+body2+html2;
		
		return result;
		
	}
	
	
	public static String generateTable(List<String> input, Integer numberOfRows){
		String output="";
		String table1 = "<table border='1'>\n";
		String table2 = "</table>\n";
		String tr1 = "<tr>\n";
		String tr2 = "</tr>\n";
		String td1 = "<td>";
		String td2 = "</td>\n";
		output=output+table1;
		
		int r = 0;
		
		
		
		output=output+tr1;
		for(int i=0;i<input.size();i++){
			
			output=output+td1+input.get(i)+td2;
			
			
			if(i<input.size()-numberOfRows){
				if (r==numberOfRows-1){
					output=output+tr2+tr1;
					r=-1;
				}
			}else{
				if (r==numberOfRows-1){
					output=output+tr2;
				}
			}
			r++;
			
			
		}
		
		
		output=output+table2;
		return output;
	}
	
	
	
	
	
	public static void escribir(String s) {

		FileWriter fichero = null;
		PrintWriter pw = null;
		try {
			fichero = new FileWriter("/home/acid/Desktop/test.html");
			pw = new PrintWriter(fichero);
			pw.println(s);

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				// Nuevamente aprovechamos el finally para
				// asegurarnos que se cierra el fichero.
				if (null != fichero)
					fichero.close();
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
	}
}
